// 构建二叉树
class TreeNode {
  constructor (key) {
    this.key = key // 节点值
    this.left = null // 左侧节点的引用
    this.right = null // 右侧节点的引用
  }
}
function ArrayBuildTree (list) {
  return helper(list, 0)
}
function helper (list, index) {
  if (index > list.length || list[index] == null || list[index] === undefined) {
    return null
  }
  let root = new TreeNode(list[index])
  root.left = helper(list, index * 2 + 1)
  root.right = helper(list, index * 2 + 2)
  return root
}
function symmetry (root) {
  if (root === null) {
    return true
  }
  return checkSymmetry(root.left, root.right)
}
function checkSymmetry (leftNode, rightNode) {
  if (leftNode === null && rightNode === null) {
    return true
  }
  if (leftNode === null || rightNode === null || leftNode.key !== rightNode.key) {
    return false
  }
  return (checkSymmetry(leftNode.left, rightNode.right) && checkSymmetry(leftNode.right, rightNode.left))
}
let root = ArrayBuildTree([1, 2, 2, 3, 4, 4, 3])
console.log(symmetry(root));
